package com.flying;

import java.util.Arrays;

/**
 * @author 刘鹏飞
 * @Classname DoubleArrayTest
 * @Date 2024/12/16 19:35
 * @Created by 刘鹏飞
 * @Description 多维数组的初始化
 */
public class DoubleArrayTest {

    public static void main(String[] args) {

        // Java中的多维数组的声明和初始化应按从低维到高维的顺序进行
        // 动态初始化
        int[][] a = new int[3][];
        a[0] = new int[2];
        a[1] = new int[5];
        a[2] = new int[3];

//        int[][] ints=new int[][2];  非法


        // 静态初始化
        int[][] ints = {
                {1, 2, 4},
                {3, 5, 9},
                {2, 56, 31}
        };

        System.out.println(Arrays.toString(ints));



        int[][] c=new int[3][];
         // c[0]={1,3,5};  错误 没有声明内部数组的类型就初始化
        c[0]=new int[]{1,4,5};
        c[1]=new int[]{12,45,21};
        c[2]=new int[]{234,453,223};

        for (int[] _C : c) {
            System.out.print(Arrays.toString(_C)+"\t");
        }

        System.out.println();
        System.out.println("=============================================");



        //  二维数组存储 Object类型的数据
        Object[ ] a1 = {1001,"高小淇",18,"讲师","2-14"};
        Object[ ] a2 = {1002,"高小七",19,"助教","10-10"};
        Object[ ] a3 = {1003,"高小琴",20,"主任","5-5"};

        Object[][] emps=new Object[3][];
        emps[0]=a1;
        emps[1]=a2;
        emps[2]=a3;

        System.out.println(Arrays.toString(emps[0]));
        System.out.println(Arrays.toString(emps[1]));
        System.out.println(Arrays.toString(emps[2]));


        System.out.println("=================遍历二维数组====================");

        for (int i = 0; i < emps.length; i++) {
            for (int j = 0; j < emps[i].length; j++) {
                System.out.print(emps[i][j]+"\t\t");
            }
            System.out.println();
        }


    }


}
